package com.thlws.redis.datatype;

import redis.clients.jedis.Jedis;

/**
 * @author HanleyTang
 * @date 2018-12-15
 */
public class JedisString {

    public static void main(String[] args) {


        try (Jedis jedis = new Jedis("localhost",6379)){
            jedis.select(11);
            jedis.flushDB();

            jedis.set("address", "China");
            System.out.println(jedis.exists("address"));
            System.out.println(jedis.strlen("address"));//获取key value的长度
            jedis.append("address", " is a great country");//在key 的value后面追加内容
            System.out.println(jedis.get("address"));


            jedis.setrange("address", 6, "coll");//修改value的部分内容
            System.out.println(jedis.get("address"));

            String rangeVal = jedis.getrange("address", 0, 4);
            System.out.println(rangeVal);


            jedis.set("age", "18");
            jedis.incr("age");//value递增
            System.out.println(jedis.get("age"));

        }

    }
}
